<?php

namespace App\Models;


class BucketLogIn extends BaseModel
{
    protected $table = "bucket_log_in";

    protected $redisTable = "bucket_log_in";

    protected $rules = [
        'admin_id' => 'required',
        'shop_id' => 'required',
        'bucket_num' => 'required',
        'type' => 'required',
        'description' => 'required',
    ];

    protected $message = [
        'admin_id.required' => '日志数据非法',
        'shop_id.required' => '日志数据非法',
        'bucket_num.required' => '日志数据非法',
        'type.required' => '日志数据非法',
        'description.required' => '日志数据非法',
    ];

    public function addLog($admin_id,$shop_id,$bucket_category_id,$bucket_num,$order_id,$worker_id,$type)
    {
        $data['admin_id'] = intval($admin_id);
        $data['shop_id'] = intval($shop_id);
        $data['order_id'] = intval($order_id);
        $data['worker_id'] = intval($worker_id);
        $data['bucket_category_id'] = intval($bucket_category_id);
        $data['bucket_num'] = intval($bucket_num);
        $data['addtime'] = time();
        $data['created_at'] = date('Y-m-d H:i:s');
        $data['updated_at'] = date('Y-m-d H:i:s');
        //1.店内期初+ 2.进货入桶+ 3.进货回桶- 4.新购水桶+ 5.售出水桶- 6.送桶- 7.回桶+ 8.零送水取桶+
        switch ($type) {
            case 1:
                $data['type'] = 1;
                $data['description'] = '店内期初';
                break;
            case 2:
                $data['type'] = 1;
                $data['description'] = '进货入桶';
                break;
            case 3:
                $data['type'] = 2;
                $data['description'] = '进货回桶';
                break;
            case 4:
                $data['type'] = 1;
                $data['description'] = '新购水桶';
                break;
            case 5:
                $data['type'] = 2;
                $data['description'] = '售出水桶';
                break;
            case 6:
                $data['type'] = 2;
                $data['description'] = '订单送桶';
                break;
            case 7:
                $data['type'] = 1;
                $data['description'] = '订单回桶';
                break;
            case 8:
                $data['type'] = 1;
                $data['description'] = '零送水取桶';
                break;
            default :
                $this->error = '非法操作';
                return false;
        }
        if (!$this->_validate($data)) {
            return false;
        }
//        tolog('login_data');
//        tolog($data);
        $res = $this->_add($data);
//        tolog('login_res----'.$res);
        if (!$res) {
            $this->error = '保存失败!';
            return false;
        }
        return $res;
    }

}